// 合并复用原则
// Composite Reuse Principle, CRP
// 
// 这里用一个司机开车的例子来解释什么是合并复用原则
// 原来实现司机又能开宝马又能开大众的代码是 在 CRP-00.hpp里的
//

#pragma once

#include <iostream>

// 不用枚举
// 用多态基类
class TaxStrategy {
public:
	TaxStrategy() {}
	virtual ~TaxStrategy() {}

	virtual double tax() = 0;

};

class TaxCN : public TaxStrategy {
public:
	TaxCN() {}
	virtual ~TaxCN() {}

	virtual double tax() override {
		return 1.0;
	}
};

class TaxUS : public TaxStrategy {
public:
TaxUS() {}
	virtual ~TaxUS() {}

	virtual double tax() override {
		return 1.32;
	}
};

class SalesOrder {
public:
	double calculateTaxCN() {
		tax = new TaxCN;
		double re = tax->tax();
		delete tax;
		return re;
	}

	double calculateTaxUS() {
		tax = new TaxUS;
		double re = tax->tax();
		delete tax;
		return re;
	}

	// double calculateTaxDE() {
	// 	tax = new Tax;
	// 	double re = tax->tax();
	// 	delete tax;
	// 	return re;
	// }

private:
	TaxStrategy *tax = nullptr;
};

int main() {
	SalesOrder sales;
	std::cout << "cn tax:" << sales.calculateTaxCN() << std::endl;

	std::cout << "US tax:" << sales.calculateTaxUS() << std::endl;

	return 0;
}
